<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>资源维护</title>

<link rel="stylesheet" type="text/css" href="../../css/cm-default.css" />
<link rel="stylesheet" type="text/css" href="../../css/main.css" />
<link rel="stylesheet" type="text/css" href="../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" />
<link rel="stylesheet" type="text/css" href="../../lib/ligerUI/skins/ligerui-icons.css" />
<link rel="stylesheet" type="text/css" href="../../lib/bootstrap/css/bootstrap.css"/>
<script type="text/javascript" src="../../lib/jquery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../lib/ligerUI/js/ligerui.all.js" ></script>
<script type="text/javascript" src="../../js/common.js" ></script>
<script type="text/javascript" src="../../lib/autoInput/AutoInput.js" ></script>
<script type="text/javascript" src="../../js/pub.js"></script>
<script type="text/javascript" src="../../lib/bootstrap/js/bootstrap.js" ></script>
<script type="text/javascript" src="../../lib/md5.js"></script>

    <script type="text/javascript">
        var defGrid;
        var defGrid2;
        var userid;

        $(function ()
        {
            roleid=window.location.toString().replace(/^[^?]+\?roleid=/,'');

            defGrid= $("#listbox1").ligerListBox({
                isShowCheckBox: true,
                isMultiSelect: true,
                valueField: 'id',
                textField: 'name',
                valueFieldID: 'test1',
                height: 240
            });
            var param = new Object();
            param.roleid=roleid;
            var data = JSON.stringify(reqJson('rbac.select.def.queryRoleResouce',param));
            ajaxSubmit("/comm/q", data, function(data) {
                defGrid.set({data: data.Rows});
            },null,false);

            defGrid2= $("#listbox2").ligerListBox({
                isShowCheckBox: true,
                isMultiSelect: true,
                valueField: 'id',
                textField: 'name',
                valueFieldID: 'test2',
                height: 240
            });

            var data2 = JSON.stringify(reqJson('rbac.select.def.queryRoleResouceyes',param));
            ajaxSubmit("/comm/q", data2, function(data) {
                defGrid2.set({data: data.Rows});
            }, null, false);
        });
        function moveToLeft()
        {
            var box1 = liger.get("listbox1"), box2 = liger.get("listbox2");

            var selecteds = box2.getSelectedItems();
            if (!selecteds || !selecteds.length) return;
            box2.removeItems(selecteds);
            box1.addItems(selecteds);

            var test2=$("#test2").val();
            if( test2.indexOf(';')<0)
            {
                var param = new Object();
                param.roleid=roleid;
                param.resourceid = test2;
                var param = JSON.stringify(reqJson('rbac.delete.def.deleRoleResource',JSON.stringify(param)));
                ajaxSubmit("/comm/d", param, function(data) {

                });
            }
            else
            {
                var result=test2.split(';');

                for(var i=0;i<result.length;i++)
                {
                    var param = new Object();
                    param.resourceid=result[i];
                    param.roleid = roleid;
                    //alert(param.resourceid);
                    var param = JSON.stringify(reqJson('rbac.delete.def.deleRoleResource',JSON.stringify(param)));
                    ajaxSubmit("/comm/d", param, function(data) {

                    });
                }
            }
        }
        function moveToRight()
        {
            var box1 = liger.get("listbox1"), box2 = liger.get("listbox2");
            var selecteds = box1.getSelectedItems();
            if (!selecteds || !selecteds.length) return;
            box1.removeItems(selecteds);
            box2.addItems(selecteds);
            var test1=$("#test1").val();
            if( test1.indexOf(';')<0)
            {
                var param = new Object();
                param.roleid=roleid;
                param.resourceid = test1;
                var data = JSON.stringify(reqJson('rbac.add.def.addRoleResourceid',JSON.stringify(param)));
                ajaxSubmit("/comm/a", data, function(data) {
                });
            }
            else
            {
                var result=test1.split(';');
                for(var i=0;i<result.length;i++)
                {
                    var param = new Object();
                    param.roleid=roleid;
                    param.resourceid = result[i];
                    var data = JSON.stringify(reqJson('rbac.add.def.addRoleResourceid',JSON.stringify(param)));
                    ajaxSubmit("/comm/a", data, function(data) {
                    });
                }
            }
        }
        function moveAllToLeft()
        {
            var box1 = liger.get("listbox1"), box2 = liger.get("listbox2");
            var selecteds = box2.data;
            if (!selecteds || !selecteds.length) return;
            box1.addItems(selecteds);
            box2.removeItems(selecteds);
            var test2=$("#test2").val();
            alert(test2);
        }
        function moveAllToRight()
        {
            var box1 = liger.get("listbox1"), box2 = liger.get("listbox2");
            var selecteds = box1.data;
            if (!selecteds || !selecteds.length) return;
            box2.addItems(selecteds);
            box1.removeItems(selecteds);

        }
    </script>
    <style type="text/css">
        .middle input {
            display: block;width:30px; margin:2px;
        }
    </style>
</head>
<body style="padding:10px">

<div style="margin:4px;float:left; font: bold;">
    未分配
    <div id="listbox1" ></div>
</div>
<div style="margin:30px;margin-top:24px;float:left;" class="middle">
    <button type="button" onclick="moveToRight();" class="form_Button btn btn-primary btn-xs">></button>
    <button type="button" onclick="moveToLeft();" class="form_Button btn btn-primary btn-xs"><</button>
    <!--  <input type="button" onclick="moveAllToLeft()" value="<<" />
    <input type="button" onclick="moveAllToRight()" value=">>" /> -->
</div>

<div style="margin:4px;float:right;font: bold;">
    已分配
    <div id="listbox2"></div>
</div>
</body>
</html>